package com.coder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coder.entity.User;
import com.coder.mapper.UserMapper;
import com.coder.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 王令
 */
@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User login(User user) {
        return getOne(new LambdaQueryWrapper<User>().select(User::getId, User::getEmail, User::getPhone, User::getNickName, User::getIdentity, User::getSummary).eq(User::getEmail, user.getEmail()).eq(User::getPass, user.getPass()));
    }

    @Override
    public Boolean register(User user) {
        if (getOne(new LambdaQueryWrapper<User>().eq(User::getEmail, user.getEmail())) == null) {
            save(user);
            return true;
        }
        return false;
    }

    @Override
    public List<User> consultant() {
        return list(new LambdaQueryWrapper<User>().eq(User::getIdentity, "咨询师"));
    }

    @Override
    public Boolean forgetValidate(User user) {
        return getOne(new LambdaQueryWrapper<User>().eq(User::getEmail, user.getEmail()).eq(User::getPhone, user.getPhone())) != null;
    }

    @Override
    public Boolean changePassword(User user) {
        return update(user, new LambdaQueryWrapper<User>().eq(User::getEmail, user.getEmail()));
    }

}
